#include "Explosion.h"

Explosion::Explosion(QObject *parent) :
    QObject(parent),
    currentFrame(0),
    isPlaying(false)
{
}

void Explosion::loadFrames(const QStringList &framePaths)
{
    frames.clear();
    for (const QString &path : framePaths) {
        QPixmap frame(path);
        if (!frame.isNull()) {
            frames.append(frame);
        }
    }
}

void Explosion::play()
{
    if (!frames.isEmpty()) {
        currentFrame = 0;
        isPlaying = true;
    }
}

QPixmap Explosion::currentPixmap()
{
    if (currentFrame >= 0 && currentFrame < frames.size()) {
        return frames[currentFrame];
    }
    return QPixmap();
}

bool Explosion::isFinished()
{
    return !isPlaying || currentFrame >= frames.size();
}

void Explosion::update()
{
    if (isPlaying && !isFinished()) {
        currentFrame++;
    }
}
